/**
 * 
 * 工具栏
 * 
 */
var saveOfType = null; // 声明全局 选择图形类型，图表类型
var chartUpdateId = null; // 声明全局 选择图形类型，图表类型
var isTablesLoad = false; // 表管理树菜单是否已加载
var map = new Map(); // 保存上下钻取时需要的数据
var drillLevel = 0; // 钻取路径
var AnyChartSwfUrl = [ biAdhocNs.sysUrl, 'assets/anychart/swf/AnyChart.swf' ]
		.join('');
biAnaly.getArrayTable = function() {
	Ext.Ajax.request({
		url : [ biAdhocNs.sysUrl, 'chart/getTables' ].join(''),
		// url : [biAdhocNs.sysUrl, 'js/data/tables.json'].join(''),
		method : 'post',
		callback : function(options, success, response) {
			if (!response.responseText == '') {
				if (success) {
					var responseMsg = Ext.util.JSON
							.decode(response.responseText);

					for (var i = 0; i < responseMsg.length; i++) {
						if (responseMsg[i].id != '') {
							var id = responseMsg[i].name;
							var type = responseMsg[i].partType;
							var item = new Ext.menu.Item({
								text : responseMsg[i].cName,
								id : id,
								type : type,
								// iconCls : ['table-icon-',
								// Math.floor(Math.random() * 10 + 1)].join(''),
								iconCls : 'table-icon-1',
								pid : 'tableChoose',
								handler : function() {
									biAnaly.tablechoose(this.id, this.type, '',
											'');
								}
							});
							Ext.getCmp('tableChoose').addItem(item);
						}
					}
				}
			} else {
				// Ext.Msg.alert('提示', '定义自定义标签失败');
			}
		}
	});
};

biAnaly.getMyTemplet = function() {
	Ext.Ajax.request({
		url : [ biAdhocNs.sysUrl, 'chart/getChartList' ].join(''),
		method : 'post',
		callback : function(options, success, response) {
			if (!response.responseText == '') {
				if (success) {
					var responseMsg = Ext.util.JSON
							.decode(response.responseText);
					for (var i = 0; i < responseMsg.length; i++) {
						if (responseMsg[i].id != '') {
							var id = responseMsg[i].chartId;
							var type = responseMsg[i].chartType;
							var item = new Ext.menu.Item({
								text : responseMsg[i].chartTitle,
								id : id,
								type : type,
								attribute : responseMsg[i],
								iconCls : 'table-icon-1',
								pid : 'myTemplet',
								handler : function() {
									biAnaly
											.templetEdit(this.id,
													this.attribute);
								}
							});
							Ext.getCmp('myTemplet').addItem(item);
						}
					}
				}
			} else {
				// Ext.Msg.alert('提示', '定义自定义标签失败');
			}
		}
	});
};
// 根据ID请求编辑
biAnaly.initViewEdit = function(editId) {
	Ext.Ajax.request({
		url : [ biAdhocNs.sysUrl, 'chart/getChartinfoById' ].join(''),
		method : 'post',
		params : {
			chartId : editId
		// 传入后台用以区分保存,编辑
		},
		callback : function(options, success, response) {
			if (!response.responseText == '') {
				if (success) {
					var resMsg = Ext.util.JSON.decode(response.responseText);
					biAnaly.templetEdit(editId, resMsg);
				}
			} else {
				// Ext.Msg.alert('提示', '定义自定义标签失败');
			}
		}
	});
};
biAnaly.picBar = {
	text : toolbar.picBar,
	id : 'picBar-manager',
	scale : 'large',
	rowspan : 1,
	iconCls : 'bar',
	iconAlign : 'top',
	width : 50,
	height : 57,
	// cls : 'x-btn-as-arrow',
	handler : function() {
		// biAnaly.picHandler();
		pictureAnalyze.chartType = 'bar';
		pictureAnalyze.drillManager = null;
		biAnaly.doShow(pictureAnalyze.chartType);
	}
};

biAnaly.picSpline = {
	text : toolbar.picSpline,
	id : 'picSpline-manager',
	scale : 'large',
	rowspan : 1,
	iconCls : 'line',
	iconAlign : 'top',
	width : 50,
	height : 57,
	// cls : 'x-btn-as-arrow',
	handler : function() {
		// biAnaly.picHandler();
		pictureAnalyze.chartType = 'spline';
		pictureAnalyze.drillManager = null;
		biAnaly.doShow(pictureAnalyze.chartType);
	}
};

/**
 * 
 * 2010-5-5 查询管理工具栏
 */
biAnaly.picPie = {
	text : toolbar.picPie,
	id : 'picPie-manager',
	scale : 'large',
	rowspan : 1,
	iconCls : 'pie',
	iconAlign : 'top',
	width : 50,
	height : 57,
	// cls : 'x-btn-as-arrow',
	handler : function() {
		// biAnaly.picHandler();
		pictureAnalyze.chartType = 'pie';
		pictureAnalyze.drillManager = null;
		biAnaly.doShow(pictureAnalyze.chartType);
	}
};

biAnaly.picBarSpline = {
	text : toolbar.picBarSpline,
	id : 'picBarSpline-manager',
	scale : 'large',
	rowspan : 1,
	iconCls : 'barline',
	iconAlign : 'top',
	width : 50,
	height : 57,
	// cls : 'x-btn-as-arrow',
	handler : function() {
		// biAnaly.picHandler();
		pictureAnalyze.chartType = 'bar,Line';
		pictureAnalyze.drillManager = null;
		biAnaly.doShow(pictureAnalyze.chartType);
	}
};

biAnaly.circularGauge = {
	text : toolbar.circularGauge,
	id : 'picCircularGauge-manager',
	scale : 'large',
	rowspan : 1,
	iconCls : 'circularGauge',
	iconAlign : 'top',
	width : 50,
	height : 57,
	// cls : 'x-btn-as-arrow',
	handler : function() {
		// biAnaly.picHandler();
		pictureAnalyze.chartType = 'circularGauge';
		pictureAnalyze.drillManager = null;
		biAnaly.doShow(pictureAnalyze.chartType);
	}
};

biAnaly.picButton = {
	xtype : 'buttongroup',
	columns : 6,
	// height:118,
	title : toolbar.picButton,
	titleCollapse : 'false',
	items : [ biAnaly.picSpline, biAnaly.picPie, biAnaly.picBar,
			biAnaly.picBarSpline, biAnaly.circularGauge ]
};

biAnaly.tableChoose = {
	text : toolbar.tableChoose,
	iconCls : 'filefilter',
	scale : 'large',
	iconAlign : 'top',
	width : 80,
	menu : {
		id : 'maintableChoose',
		items : [ {
			text : toolbar.maintableChoose,
			menu : {
				id : 'tableChoose',
				items : []
			}
		}, {
			text : toolbar.maintableModify,
			menu : {
				id : 'myTemplet',
				items : []
			}
		} ]
	},
	handler : function() {
		// 表管理树菜单如果已加载，则不在重复加载
		if (!isTablesLoad) {
			isTablesLoad = true;
			biAnaly.getArrayTable();
			biAnaly.getMyTemplet();
		}
	}
};

biAnaly.tablechoose = function(id, type, x_Field, cy_Field) {

	var childNodes = Ext.getCmp('picturetree').root.childNodes;
	
	var flag = 0; // 定义判断flag标志 
	if(childNodes.length > 0) {
			for (var i=0; i<childNodes.length; i++) {
				if(id == 0) {  //图表修改
					var cField = cy_Field.yQueryBean.MAIN_TABLE;
					if(cField[0].TABLENAME == childNodes[i].id) {
						flag++;
						Ext.Msg.show({
							title : toolbar.msgTitle,
							modal : true,
							msg : toolbar.editSelectMsg,
							buttons : Ext.Msg.OK,
							width : 220
						});
						return;
						
					}
				}  else {  //宽表选择
					if( id == childNodes[i].id) {
						flag++;
						Ext.Msg.show({
							title : toolbar.msgTitle,
							modal : true,
							msg : toolbar.tableSelectionMsg,
							buttons : Ext.Msg.OK,
							width : 200
						});
						return;
					} 
				}
		}
		
		if(flag == 0) {   //定义flag,如果之前未选择该表，则创建tree
			biAnaly.toCreateTree(id, type, x_Field, cy_Field);
		}
		
	} else {
		biAnaly.toCreateTree(id, type, x_Field, cy_Field);
	}
};

biAnaly.toCreateTree = function(id, type, x_Field, cy_Field) {
//	Ext.getCmp('pic-edit-panel').cleanAllColumn();
//	Ext.getCmp('picturetree').removeAll(true);
	
//	Ext.getCmp('picturetree').checkAttributes.each(function(tempObj) {
//		Ext.getCmp('picturetree')
//				.getNodeById(biAdhocNs.TableTreePanel.changeId).findChild('id',
//						tempObj.id).getUI().toggleCheck(false);
//	});
//	Ext.getCmp('picturetree').checkAttributes.clear();
	biAdhocNs.TableTreePanel.changeId = id;
	var uxtreePanel = Ext.getCmp('picturetree');

	biAnaly.picEditPanel.removeMonthFilter();

	var mask = new Ext.LoadMask(uxtreePanel.body, {
		removeMask : true,
		msg : toolbar.tableChooseMask
	});
	mask.show();
	Ext.Ajax.request({
		url : [ biAdhocNs.sysUrl, 'chart/getTreeNodes' ].join(''),
		params : {
			"changeId" : id
		},
		success : function(result, request) {
			var data = Ext.util.JSON.decode(result.responseText);
			var chartJson = x_Field.chartConfigJson;
			if (x_Field.xFieldCd == '0') {
				x_Field = '';
			}
			if (data != null && data != 'undefined') {
				pictureAnalyze.chartType = x_Field.chartType;
				uxtreePanel
						.createTree(data, mask, x_Field, cy_Field, chartJson);
			}
		},
		failure : function(result, request) {
			if (mask) {
				mask.hide();
			}
			Ext.Msg.alert(toolbar.msgTitle, toolbar.tableChooseMsgContent);
		}
	});
}


biAnaly.tableManger = {
	xtype : 'buttongroup',
	columns : 2,
	title : toolbar.tableManger,
	titleCollapse : 'false',
	items : [ biAnaly.tableChoose ]
};

// 上钻按钮
biAnaly.upDrillBtn = {
	text : toolbar.upDrillBtn,
	scale : 'large',
	rowspan : 1,
	iconCls : 'drill-open-icon',
	iconAlign : 'top',
	width : 80,
	handler : function() {
		if (drillLevel < 1) {
			Ext.getCmp('upDrill').hide();
		} else if (drillLevel == 1) {
			biAnaly.doShow(pictureAnalyze.chartType);
			drillLevel = 1;
			drillLevel--;
			Ext.getCmp('upDrill').hide();
		} else {
			var CnodeId = map.get('CnodeId');
			var id = map.get(drillLevel - 2);
			drillLevel--;
			CnodeId[0] = id;// 条件值，条件字段
			var XnodeId = map.get('XnodeId');
			//多表关联数据传递
		    var M_RelationData = Ext.getCmp('picturetree').getMultiRelationData();
			var url = [ biAdhocNs.sysUrl, 'chart/chart/showTemplates' ]
					.join('');
			// var yArray = Ext.getCmp("numerical").items.items;
			var pro = Ext.getCmp("anychart-prop-grid").getSource();
			// 筛选条件
			var C_Fields = Ext.getCmp('pic-edit-panel')
					.getReportFilter(CnodeId);
			// X轴
			var X_Fields = Ext.getCmp('pic-edit-panel').getJoinTableClause(
					XnodeId[1]);
			// Y轴
			var Y_Fields = Ext.getCmp('pic-edit-panel').getY_Fields();
			Ext.Ajax.request({
				url : url,
				timeout : 3600000,
				method : 'POST',
				params : {
					chartType : pictureAnalyze.chartType,
					strJson : Ext.util.JSON.encode(pro),
					cFields : Ext.util.JSON.encode(C_Fields),
					xFields : Ext.util.JSON.encode(X_Fields),
					yFields : Ext.util.JSON.encode(Y_Fields),
					chartId : null, // 传入后台用以区分保存,编辑
					dataitemsId : null,
					paramId : null,
					//多表关联数据传递
					mulRelationData: Ext.util.JSON.encode(M_RelationData)
				},
				callback : function(options, success, response) {
					if (success == true) {
						var chartDiv = Ext.get("drop-div").id;
						var chart = new AnyChart(AnyChartSwfUrl);
						chart.wMode = 'transparent';
						chart.width = '100%';
						chart.height = '100%';
						chart.setXMLData(response.responseText);
						chart.write(chartDiv);
					}
				}
			});
		}
	}
};

biAnaly.brownseSqlBtn = {
	text : toolbar.brownseSql.btn,
	scale : 'large',
	rowspan : 1,
	iconCls : 'sql',
	iconAlign : 'top',
	width : 90,
	// cls : 'x-btn-as-arrow',
	handler : function() {
		/*if (saveOfType == null) {
			Ext.Msg.show({
				title : toolbar.msgTitle,
				modal : true,
				msg : toolbar.brownseSql.msgShowContent,
				buttons : Ext.Msg.OK,
				width : 200
			});
			return;
		} else {
			if (biAnaly.picEditPanel.validate(saveOfType)) { // 校验字段配置是否正确 */
				//多表关联验证
				if(biAnaly.valiRelative() == true) { 
					// 筛选条件
					var C_Fields = Ext.getCmp('pic-edit-panel').getReportFilter('');
					// X轴
					var X_Fields = Ext.getCmp('pic-edit-panel').getJoinTableClause(
							'');
					// Y轴
					var Y_Fields = Ext.getCmp('pic-edit-panel').getY_Fields();
					//多表关联数据传递
				    var M_RelationData = Ext.getCmp('picturetree').getMultiRelationData();
					var url = [ biAdhocNs.sysUrl, 'chart/browseSql4Pic.action' ]
							.join('');
					Ext.Ajax.request({
						url : url,
						timeout : 3600000,
						method : 'POST',
						params : {
							CFields : Ext.encode(C_Fields),
							XFields : Ext.encode(X_Fields),
							YFields : Ext.encode(Y_Fields),
							//多表关联数据传递
							mulRelationData: Ext.util.JSON.encode(M_RelationData)
						},
						callback : function(options, success, response) {
							var resultJson = Ext.decode(response.responseText);
	
							var success = resultJson.success;
							var msg = resultJson.msg;
							var sql = resultJson.sql;
	
							if (success == true) {
								Ext.Msg.alert(toolbar.brownseSql.msgTitle,
										toolbar.brownseSql.msgSucContent + sql);
							} else {
								Ext.Msg.alert(toolbar.brownseSql.msgTitle,
										toolbar.brownseSql.msgFailContent + msg);
							}
						}
					});
				}
			/*}
		}*/
	}

};

/**
 * 获取维度信息
 */
biAnaly.getDemensionData = function(columnId) {
	var url = [ biAdhocNs.sysUrl, 'chart/getDemensionDataByColumnId' ].join('');
	var para = [ 'columnId=', columnId ].join('');
	var rs = biAnaly.synchronizationAjax(url, para);
	return rs;
};

/**
 * 同步请求方法
 */
biAnaly.synchronizationAjax = function(url, para) {
	function createXhrObject() {
		var http;
		var activeX = [ 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP',
				'Microsoft.XMLHTTP' ];
		try {
			http = new XMLHttpRequest();
		} catch (e) {
			for (var i = 0; i < activeX.length; ++i) {
				try {
					http = new ActiveXObject(activeX[i]);
					break;
				} catch (e) {
				}
			}
		} finally {
			return http;
		}
	}
	;

	var conn = createXhrObject();
	if (para != null && para != '' && typeof (para) != 'undefined') {
		url = [ url, '?', para ].join('');
	}
	conn.open("GET", url, false);
	conn.send(null);
	if (conn.responseText != '') {
		var rs;
		try {
			rs = Ext.util.JSON.decode(conn.responseText);
		} catch (e) {
			return null;
		}
		return rs;
	} else {
		return null;
	}
};

biAnaly.executeManage = {
	xtype : 'buttongroup',
	columns : 5,
	title : toolbar.executeManage,
	titleCollapse : 'false',
	items : [ biAnaly.brownseSqlBtn ]
};

/**
 * 上钻管理
 */
biAnaly.upDrillManager = {
	id : 'upDrill',
	xtype : 'buttongroup',
	columns : 5,
	title : toolbar.upDrillManager,
	titleCollapse : 'false',
	hidden : 'true',
	items : [ biAnaly.upDrillBtn ]
};

/**
 * 验证多表是否配置了关联关系
 */
biAnaly.valiRelative = function(){
	var childNodes = Ext.getCmp('picturetree').root.childNodes;
	if(childNodes.length == 1) {
		return true;
	}
	if(childNodes.length > 1) {
		var relaPanel = Ext.getCmp("editGridPanelOfColumns");
		var comp = Ext.getCmp('picturetree');
		if(relaPanel == undefined) {
			Ext.Msg.show({
				title : toolbar.msgTitle,
				modal : true,
				msg : toolbar.valiRelativeMsg,
				buttons : Ext.Msg.OK,
				width : 300
			});
			return false;
		} else if(relaPanel != undefined){
			if (relaPanel.store.modified.length < 1 ) {
				Ext.Msg.show({
					title : toolbar.msgTitle,
					modal : true,
					msg : toolbar.valiRelativeMsg,
					buttons : Ext.Msg.OK,
					width : 300
				});
				return false;
			} else {
				return true;
			}
		}
	}
};


/**
 * 显示图表
 */
biAnaly.doShow = function(chartType) {
	if(biAnaly.valiRelative() == true){  //多表关联验证
		if (biAnaly.picEditPanel.validate(chartType)) {
			saveOfType = chartType;
			// 初始化钻取级别
			drillLevel = 0;
			Ext.getCmp('upDrill').hide();
			map.clear();
			var url = [ biAdhocNs.sysUrl, 'chart/chart/showTemplates' ].join('');
			// var yArray = Ext.getCmp("numerical").items.items;
			var pro = Ext.getCmp("anychart-prop-grid").getSource();
	
			// 筛选条件
			var C_Fields = Ext.getCmp('pic-edit-panel').getReportFilter('');
			// X轴
			var X_Fields = Ext.getCmp('pic-edit-panel').getJoinTableClause('');
			// Y轴
			var Y_Fields = Ext.getCmp('pic-edit-panel').getY_Fields();
			//多表关联数据传递
		    var M_RelationData = Ext.getCmp('picturetree').getMultiRelationData();
			//var href = "";
			var language=document.getElementById('myhidden').value;
			language=language.substr(0).replace("_","-");
			/*if (location.href.indexOf("?") > 0) {
				href = location.href.split("?")[1];
				href = href.substr(5, 5).replace("_", "-");
			}*/
			Ext.Ajax
					.request({
						url : url,
						timeout : 3600000,
						method : 'POST',
						headers : {
							'Accept-Language' : language
						},
						params : {
							chartType : chartType,
							strJson : Ext.util.JSON.encode(pro),
							cFields : Ext.util.JSON.encode(C_Fields),
							xFields : Ext.util.JSON.encode(X_Fields),
							yFields : Ext.util.JSON.encode(Y_Fields),
							mulRelationData: Ext.util.JSON.encode(M_RelationData),
							chartId : null, // 传入后台用以区分保存,编辑
							dataitemsId : null,
							paramId : null
						},
						callback : function(options, success, response) {
							if (success == true) {
								if (response.responseText.indexOf("org.nutz.dao.DaoException") > 0) {
									Ext.Msg.show({
										title : toolbar.msgTitle,
										modal : true,
										msg : toolbar.doShowSqlMsg,
										buttons : Ext.Msg.OK,
										width : 200
									});
								} else if (response.responseText
										.indexOf("Exception!") > 0) {
									Ext.Msg.show({
										title : toolbar.msgTitle,
										modal : true,
										msg : toolbar.doShowMsg,
										buttons : Ext.Msg.OK,
										width : 200
									});
								} else {
									var chartDiv = Ext.get("drop-div").id;
									var chart = new AnyChart(AnyChartSwfUrl, [
											biAdhocNs.sysUrl,
											'assets/anychart/swf/Preloader.swf' ]
											.join(''));
									chart.wMode = 'transparent';
									chart.width = '100%';
									chart.height = '100%';
									chart.setXMLData(response.responseText);
									chart.addEventListener('pointClick',
											biAnaly.picOnClick);
									chart.write(chartDiv);
								}
							}
						}
					});
		}
	}
};

/**
 * 保存图表
 */
biAnaly.toSave = {
	text : toolbar.toSave,
	scale : 'large',
	rowspan : 1,
	iconCls : 'save',
	iconAlign : 'top',
	width : 80,
	handler : function() {
		if (saveOfType == null) {
			Ext.Msg.show({
				title : toolbar.msgTitle,
				modal : true,
				msg : toolbar.toSaveMsg,
				buttons : Ext.Msg.OK,
				width : 200
			});
			return;
		}
		var url = [ biAdhocNs.sysUrl, 'chart/chartSave' ].join('');
		// var xAsixValue = "";
		// xAsixValue = Ext.getCmp(xAsix).text;

		var pro = Ext.getCmp("anychart-prop-grid").getSource();

		// 筛选条件
		var C_Fields = Ext.getCmp('pic-edit-panel').getReportFilter('');
		// X轴
		var X_Fields = Ext.getCmp('pic-edit-panel').getJoinTableClause('');
		// Y轴
		var Y_Fields = Ext.getCmp('pic-edit-panel').getY_Fields();
		//多表关联数据传递
		var M_RelationData = Ext.getCmp('picturetree').getMultiRelationData();
		Ext.Ajax.request({
			url : url,
			timeout : 3600000,
			method : 'GET',
			params : {
				chartType : saveOfType,
				strJson : Ext.util.JSON.encode(pro),
				// xAsixValue: xAsixValue,
				cFields : Ext.util.JSON.encode(C_Fields),
				xFields : Ext.util.JSON.encode(X_Fields),
				yFields : Ext.util.JSON.encode(Y_Fields),
				chartId : chartUpdateId, // 传入后台用以区分保存,编辑
				dataitemsId : null,
				paramId : null,
				//多表关联数据传递
				mulRelationData: Ext.util.JSON.encode(M_RelationData)
			},
			callback : function(options, success, response) {
				if (success == true) {
					Ext.Msg.show({
						title : toolbar.msgTitle,
						modal : true,
						msg : toolbar.toSaveSucMsg,
						buttons : Ext.Msg.OK,
						width : 200
					});
				} else {
					Ext.Msg.show({
						title : toolbar.msgTitle,
						modal : true,
						msg : toolbar.toSaveFailMsg,
						buttons : Ext.Msg.OK,
						width : 200
					});
				}
			}
		});

	}
};

/**
 * 保存图形信息
 */
biAnaly.saveInfo = {
	xtype : 'buttongroup',
	columns : 5,
	title : toolbar.saveInfo,
	titleCollapse : 'false',
	items : [ biAnaly.toSave ]
};

/**
 * 数据库中的图表预览
 */
biAnaly.templetEdit = function(id, att) {
	// 加载x y 筛选 图例信息
	// var nodeinfo=this.getNodeById(att.xFieldCd);
	biAnaly.viewEdit(att.chartId);
	biAnaly.getFieldInfo("yField", id, att);

};

biAnaly.viewEdit = function(chartId) {
	var url = [ biAdhocNs.sysUrl, 'chart/viewEditChart?chartId=' + chartId ]
			.join('');
//	var href = "";
//	if (location.href.indexOf("?") > 0) {
//		href = location.href.split("?")[1];
//		href = href.substr(5, 5).replace("_", "-");
//	}
	var language=document.getElementById('myhidden').value;
	language=language.substr(0).replace("_","-");
	Ext.Ajax.request({
		url : url,
		timeout : 3600000,
		method : 'POST',
		headers : {
			'Accept-Language' : language
		},
		params : {},
		callback : function(options, success, response) {
			if (success == true) {
				var chartDiv = Ext.get("drop-div").id;
				var chart = new AnyChart(AnyChartSwfUrl);
				chart.wMode = 'transparent';
				chart.width = '100%';
				chart.height = '100%';
				chart.setXMLData(response.responseText);
				chart.write(chartDiv);
			}
		}
	});
};

/**
 * 国际化
 */
biAnaly.i18n = {
	xtype : 'buttongroup',
	columns : 6,
	// height:118,
	title : toolbar.i18n,
	titleCollapse : 'false',
	items : [ {
		text : toolbar.i18nEn,
		id : 'i18n-en',
		scale : 'large',
		rowspan : 1,
		iconCls : 'line',
		iconAlign : 'top',
		width : 80,
		height : 57,
		handler : function() {
			var url = location.href;
			var url2 = [ biAdhocNs.sysUrl, 'chart/i18n' ].join('');
			Ext.Ajax.request({
				url:url2,
				method:"post",
				params:{
					language:"en_US"
				},
				callback : function(options, success, response) {
					window.location = url;
				}
			});
		}
	}, {
		text : toolbar.i18nZh,
		id : 'i18n-zh',
		scale : 'large',
		rowspan : 1,
		iconCls : 'pie',
		iconAlign : 'top',
		width : 80,
		height : 57,
		handler : function() {
			var url = location.href;
			var url2 = [ biAdhocNs.sysUrl, 'chart/i18n' ].join('');
			Ext.Ajax.request({
				url:url2,
				method:"post",
				params:{
					language:"zh_CN"
				},
				callback : function(options, success, response) {
					if (success == true) {
						window.location = url;
					}
				}
			});
		}
	} ]
};

/**
 * 图形点单击事件
 * 
 * @deprecated 用于处理单击图形时的操作
 */
drillFunName = function(id, val) {
	if (false) {
		// 钻取条件
	}
	var array = Ext.getCmp('axis-column').items.items;
	var nodeIdUrl = array[0].namePath;
	var nodeIdArray = nodeIdUrl.split(">");
	if (nodeIdArray.length < 2) {
		Ext.MessageBox.alert(toolbar.msgTitle, toolbar.drillFunNameMsg);
		return;
	}
	var XnodeId = nodeIdArray[drillLevel + 1].split(".");
	var CnodeId = nodeIdArray[drillLevel].split(".");
	CnodeId[0] = id;// 条件值，条件字段
	map.put(drillLevel, id);
	map.put('CnodeId', CnodeId);
	map.put('XnodeId', XnodeId);
	// 当钻取等级 < 数组个数（length-1）-2 时才可以进行下钻
	if (drillLevel < nodeIdArray.length) {
		//多表关联数据传递
	    var M_RelationData = Ext.getCmp('picturetree').getMultiRelationData();
		var url = [ biAdhocNs.sysUrl, 'chart/chart/showTemplates' ].join('');
		// var yArray = Ext.getCmp("numerical").items.items;
		var pro = Ext.getCmp("anychart-prop-grid").getSource();
		// 筛选条件
		var C_Fields = Ext.getCmp('pic-edit-panel').getReportFilter(CnodeId);
		// X轴
		var X_Fields = Ext.getCmp('pic-edit-panel').getJoinTableClause(
				XnodeId[1]);
		// Y轴
		var Y_Fields = Ext.getCmp('pic-edit-panel').getY_Fields();
		Ext.Ajax.request({
			url : url,
			timeout : 3600000,
			method : 'POST',
			params : {
				chartType : pictureAnalyze.chartType,
				strJson : Ext.util.JSON.encode(pro),
				cFields : Ext.util.JSON.encode(C_Fields),
				xFields : Ext.util.JSON.encode(X_Fields),
				yFields : Ext.util.JSON.encode(Y_Fields),
				chartId : null, // 传入后台用以区分保存,编辑
				dataitemsId : null,
				paramId : null,
				//多表关联数据传递
				mulRelationData: Ext.util.JSON.encode(M_RelationData)
			},
			callback : function(options, success, response) {
				if (success == true) {
					var chartDiv = Ext.get("drop-div").id;
					var chart = new AnyChart(AnyChartSwfUrl);
					chart.wMode = 'transparent';
					chart.width = '100%';
					chart.height = '100%';
					chart.setXMLData(response.responseText);
					chart.write(chartDiv);
				}
			}
		});
		drillLevel++; // 向下钻取
	}
	// 显示上钻按钮
	Ext.getCmp('upDrill').show();
};

biAnaly.getFieldInfo = function(field, chartId, att) {
	// var array = new Array();
	Ext.Ajax.request({
		url : [ biAdhocNs.sysUrl, 'chart/chart/chartDetail' ].join(''),
		method : 'post',
		params : {
			field : field,
			chartId : chartId
		},
		callback : function(options, success, response) {
			if (!response.responseText == '') {
				if (success) {
					// 先加载表
					
					if(att.ext3 != null) {   //区分多表关联，及单表
						var tempStr = att.ext3;
						var tableNames = tempStr.split(",");
						for(var i=0; i< tableNames.length; i++) {
							if(tableNames[i] != '') {
								biAnaly.tablechoose(tableNames[i], "", att, Ext.util.JSON
										.decode(response.responseText));
							}
						}
					} else {
						var tableName = att.xFieldTableName;
						biAnaly.tablechoose(tableName, "", att, Ext.util.JSON
								.decode(response.responseText));
					}
					saveOfType = att.chartType;
					chartUpdateId = att.chartId;
				}
			} else {
				Ext.Msg.alert(toolbar.msgTitle, toolbar.getFieldInfoMsg);
			}
		}
	});
};

// map方法，存放键值对
function Map() {
	this.elements = new Array();
	// 获取MAP元素个数
	this.size = function() {
		return this.elements.length;
	};

	// 判断MAP是否为空
	this.isEmpty = function() {
		return (this.elements.length < 1);
	};

	// 删除MAP所有元素
	this.clear = function() {
		this.elements = new Array();
	};

	// 向MAP中增加元素（key, value)
	this.put = function(_key, _value) {
		this.elements.push({
			key : _key,
			value : _value
		});
	};

	// 删除指定KEY的元素，成功返回True，失败返回False
	this.remove = function(_key) {
		var bln = false;
		try {
			for (var i = 0; i < this.elements.length; i++) {
				if (this.elements[i].key == _key) {
					this.elements.splice(i, 1);
					return true;
				}
			}
		} catch (e) {
			bln = false;
		}
		return bln;
	};

	// 获取指定KEY的元素值VALUE，失败返回NULL
	this.get = function(_key) {
		try {
			for (var i = 0; i < this.elements.length; i++) {
				if (this.elements[i].key == _key) {
					return this.elements[i].value;
				}
			}
		} catch (e) {
			return null;
		}
	};

	// 获取指定索引的元素（使用element.key，element.value获取KEY和VALUE），失败返回NULL
	this.element = function(_index) {
		if (_index < 0 || _index >= this.elements.length) {
			return null;
		}
		return this.elements[_index];
	};

	// 判断MAP中是否含有指定KEY的元素
	this.containsKey = function(_key) {
		var bln = false;
		try {
			for (var i = 0; i < this.elements.length; i++) {
				if (this.elements[i].key == _key) {
					bln = true;
				}
			}
		} catch (e) {
			bln = false;
		}
		return bln;
	};

	// 判断MAP中是否含有指定VALUE的元素
	this.containsValue = function(_value) {
		var bln = false;
		try {
			for (var i = 0; i < this.elements.length; i++) {
				if (this.elements[i].value == _value) {
					bln = true;
				}
			}
		} catch (e) {
			bln = false;
		}
		return bln;
	};

	// 获取MAP中所有VALUE的数组（ARRAY）
	this.values = function() {
		var arr = new Array();
		for (var i = 0; i < this.elements.length; i++) {
			arr.push(this.elements[i].value);
		}
		return arr;
	};

	// 获取MAP中所有KEY的数组（ARRAY）
	this.keys = function() {
		var arr = new Array();
		for (var i = 0; i < this.elements.length; i++) {
			arr.push(this.elements[i].key);
		}
		return arr;
	};
};